var delayTime = 0;
var userphone = $("#userphone"), vercode = $("#vercode"), codeBtn = $("#codeBtn"), bindChecked = $("#bindChecked");

// 获取验证码点击事件
function onGetVercodeClick() {
	if (codeBtn.hasClass("disabled")) return;
	
	mobileGlobal.sendRequest(__ctx + "/nr/api/aliyun/getVercode.xhtml", {userphone : userphone.val()}, "正在发送验证码...", function(data, status) {
		mobileGlobal.hideLoading();
		if (data.status) {
			delayTime = 60;
			codeBtn.addClass("disabled");
			codeBtn.children("span").text(delayTime + "s");
			setTimeout(timeoutHandler, 1000);
		} else {
			mobileGlobal.failed("发送验证码失败");
		}
	});
}

//超时处理器
function timeoutHandler() {
	delayTime --;
	if (delayTime <= 0) {
		codeBtn.removeClass("disabled");
		codeBtn.children("span").text("");
		return;
	}
	
	codeBtn.children("span").text(delayTime + "s");
	setTimeout(timeoutHandler, 1000);
}

// 绑定选择点击事件
function onBindCheckClick() {
	var checked = !bindChecked.is(":checked");
	bindChecked.prop("checked", checked);
}

// 登录点击事件
function onLoginClick() {
	var data = {
		userphone : userphone.val(), 
		vercode : vercode.val(), 
		boundwx : bindChecked.is(":checked")
	};
	
	mobileGlobal.sendRequest(__ctx + "/nr/mlogin.xhtml", data, "正在登录...", function(data, status) {
		mobileGlobal.hideLoading();
		if (data.status) mobileGlobal.forward(data.result);
		else mobileGlobal.failed(data.result);
	});
}

// 注册点击事件
function onRegisterClick() {
	mobileGlobal.forward(__ctx + "/nr/register.xhtml");
}